package view;

import control.PassengerController;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/***This is the frame after login,
 * It will ask the user to choose service or VIP service
 * User must choose a sevice before they do to the next step.
 * In this version, the function make change is not implemented.
 ***/

public class www extends JFrame {
    JButton btn;
    public static JFrame jfra;
    private static JPanel pane1,myPanel,jpan1;
    public static PassengerController passengerController = new PassengerController();
    public static LogIn logIn = new LogIn();
    public static String bookNumber = logIn.bookNumber;
    public static ImageIcon background;
    public static JLabel company, MyTripLabel, LogInLabel, ServiceLabel, VIPLabel, ModifyLabel, ContactLabel,label;


    public www() {
        jfra = new JFrame();
//setting the background
        background = new ImageIcon("src/view/image/background.png"); //Create a background image
        label = new JLabel(background);  //Add a background image to the label
        label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());//Set the label to be as wide as the image
        myPanel = (JPanel) jfra.getContentPane();  //Set myPanel to the Content panel
        myPanel.setOpaque(false);  //Make my panel invisible
        myPanel.setLayout(new FlowLayout());  //Set my panel to a flow layout
        jfra.getLayeredPane().setLayout(null);//Leave the layout of the layered panel blank


        //create bar
        jpan1 = new JPanel();
        company = new JLabel("          Check-In Kiosk                    ", JLabel.LEFT);
        Font fnt = new Font("Serief", Font.BOLD, 40);
        company.setFont(fnt);
        LogInLabel = new JLabel("LogIn          ", JLabel.RIGHT);
        LogInLabel.setBackground(Color.YELLOW);
        MyTripLabel = new JLabel("MyTrip          ", JLabel.RIGHT);
        ServiceLabel = new JLabel("Service         ", JLabel.RIGHT);
        VIPLabel = new JLabel("VIP         ", JLabel.RIGHT);
        ModifyLabel = new JLabel("Board         ", JLabel.RIGHT);
        ContactLabel = new JLabel("Contact           ", JLabel.RIGHT);
        company.setForeground(Color.blue);
        jpan1.add(company);
        jpan1.add(LogInLabel);
        jpan1.add(MyTripLabel);
        jpan1.add(ServiceLabel);
        jpan1.add(VIPLabel);
        jpan1.add(ModifyLabel);
        jpan1.add(ContactLabel);
        jpan1.setVisible(true);
        myPanel.add(jpan1);

//content part
        JPanel pan1 = new JPanel();
        pan1.setLayout(new GridLayout(4, 1));
        pan1.setPreferredSize(new Dimension(320,420));
        myPanel.add(pan1,BorderLayout.CENTER);

//        jpan.setSize(200, 200);
//        jpan.setBounds(300,300,200,200);
//        pane1 = new JPanel();
        JPanel panlab=new JPanel();
        JLabel l1 = new JLabel("Service you need:");
        Font fnt3 = new Font("Serief", Font.CENTER_BASELINE, 26);
        l1.setFont(fnt3);
        panlab.add(l1);
        panlab.setVisible(true);
        Font fnt1 = new Font("Serief", Font.ROMAN_BASELINE, 20);
        JPanel jpanc1=new JPanel();
        JRadioButton c1 = new JRadioButton("economy class", true);      // create a group of three radio buttons.
        c1.setFont(fnt1);
        jpanc1.add(c1);
        jpanc1.setVisible(true);

        JPanel jpanc2=new JPanel();
        JRadioButton c2 = new JRadioButton("first class");
        c2.setFont(fnt1);
        jpanc2.add(c2);
        jpanc2.setVisible(true);
        // c1 for economy class, c2 for VIP , c3 for change
//        JRadioButton c3 = new JRadioButton("make changes");
        ButtonGroup group = new ButtonGroup();
                              // create a label
        group.add(c1);
        group.add(c2);
//        group.add(c3);
        pan1.add(panlab,BorderLayout.CENTER);
        pan1.add(jpanc1,BorderLayout.CENTER);
        pan1.add(jpanc2,BorderLayout.CENTER);
//        pane1.add(c3);

        JPanel panbtn=new JPanel();
        panbtn.setPreferredSize(new Dimension(100,90));
        btn = new JButton("Confirm");
        Font fnt2 = new Font("Serief", Font.PLAIN, 20);
        btn.setFont(fnt2);
        panbtn.add(btn);
        panbtn.setVisible(true);

//        jpan.add(pane1);
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pan1.add(panbtn);
        pan1.setVisible(true);

        //Set myPanel
        jfra.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
//Set interface properties
        jfra.setBounds(300, 300, background.getIconWidth(), background.getIconHeight());
        jfra.setVisible(true);
        jfra.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        btn.addActionListener(new ActionListener() {             //add listener to the radiobutton
            @Override
            public void actionPerformed(ActionEvent e) {
                if (c1.isSelected() == true) {
                    jfra.setVisible(false);
                    new MealSeat();
                }// service
                else if (c2.isSelected() == true) {
//                    passengerController.chooseService(bookNumber,"first class");
                    jfra.setVisible(false);
                    new MealSeatVIP();
                }  // vip
                else if (c2.isSelected() == true) {
                }  //
                else {
                    JOptionPane.showMessageDialog(null, "Please choose a service!");
                }
            }
        });



    }
}
